package com.me.chat.config;

import com.me.chat.mapper.user.UserMapper;
import com.me.chat.pojo.suport.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;


@Service
public class SecuritySecertConfig implements UserDetailsService {

    @Autowired
    UserMapper userMapper;
    @Override
    public UserDetails loadUserByUsername(String usernaem) throws UsernameNotFoundException {
        User user = userMapper.selOneUser(usernaem);
        if(user==null){
            throw new UsernameNotFoundException("用户名不存在");
        }
        user.setRoles(userMapper.getUserRole(user.getId()));
        return user;
    }
}
